﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Winter.BackEnd.Models.Domain;
using System.Reflection;
using System.Data.SqlTypes;

namespace Winter.BackEnd.Models.DataTypes
{
    public class EventDTO
    {
        #region fields
        private string _event_length;
        private string _rec_type;
        #endregion
        #region properties
        public string start_date { get; set; }
        public string end_date { get; set; }
        public string text { get; set; }
        public string custom_data { get; set; }
        public string event_length
        {
            get
            {

                return _event_length != "null" ? _event_length : null;
            }
            set { _event_length = value; }
        }
        public string rec_type
        {
            get
            {

                return _rec_type != "null" ? _rec_type : null;
            }
            set { _rec_type = value; }
        }
        public string event_pid { get; set; }
        #endregion
        public static explicit operator Event(EventDTO eventInstance)
        {

            Event targetEvent = new Event()
            {
                Description = eventInstance.text,
                EventStartTime = !eventInstance.start_date.Contains("9999") ?
                                DateTime.ParseExact(eventInstance.start_date, "yyyy.MM.dd HH.mm.ss", null) : DateTime.Now,
                EventEndTime = !eventInstance.end_date.Contains("9999") ?
                               DateTime.ParseExact(eventInstance.end_date, "yyyy.MM.dd HH.mm.ss", null) : SqlDateTime.MaxValue.Value,
                event_length = !string.IsNullOrEmpty(eventInstance.event_length) ?
                (int?)int.Parse(eventInstance.event_length) : null,
                rec_type = eventInstance.rec_type
            };

            return targetEvent;
        }
    }
}
